from PyQt5.QtWidgets import QTableWidgetItem

from apps.myfrm.views import MyFrmDataView


class MyFrmLoader:

    def __init__(self, frame, signals):
        self.frame = frame
        self.signals = signals

    def load(self):
        view = MyFrmDataView()
        res = view.get()
        print('res', res)
        if res['data']:
            self.insert(res['data']['res'])

    def insert(self, data):
        row = len(data)
        self.frame.tableWidget.setRowCount(row)
        for r in range(row):
            item0 = QTableWidgetItem(str(data[r].id))
            item1 = QTableWidgetItem(str(data[r].title))

            self.frame.tableWidget.setItem(r, 0, item0)
            self.frame.tableWidget.setItem(r, 1, item1)